﻿using System.Collections.Generic;
using System.Linq;
using Model.Repositories;

namespace Presenter.Users
{
    public class UserAllPresenter
    {
        private IUserAllView _view;

        public UserAllPresenter(IUserAllView view)
        {
            _view = view;

            _view.GetAll(GetAll());
        }

        public void Reload(IUserAllView view)
        {
            _view = view;

            _view.GetAll(GetAll());
        }

        List<List<string>> GetAll()
        {
            var result = new List<List<string>>();

            var obj = RepositoryManager.Instance.UserRepository.GetAll();
            if (obj != null && obj.Count != 0)
            {
                result.AddRange(obj.Select(user => new List<string>
                                                       {
                                                           user.Id.ToString(), user.Email, user.NickName, user.FullName, user.Job, user.BirthDay.ToShortDateString()
                                                       }));
            }

            return result;
        }
    }
}

